package com.yangye.cloud.demo.pay.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.QueueBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author yangye
 * @date 2020/08/19
 */
@Configuration
public class RabbitmqConfig {

	@Bean
	public DirectExchange directExchange() {
		return new DirectExchange("yangye-direct-exchange");
	}

	@Bean
	public Queue directQueue() {
		return QueueBuilder.durable("yangye-direct-queue")
				.withArgument("x-dead-letter-exchange", "yangye-dlx-exchange")// 死信队列交换机
				.withArgument("x-dead-letter-routing-key", "yangye-dlx-routing-key")// 死信队列routing-key
				.withArgument("x-message-ttl", 3000)
				.build();
	}

	@Bean
	public Binding directBinding() {
		return BindingBuilder.bind(directQueue()).to(directExchange()).with("yangye-direct-routing-key");
	}

	@Bean
	public DirectExchange dlxExchange() {
		return new DirectExchange("yangye-dlx-exchange");
	}

	@Bean
	public Queue dlxQueue() {
		return new Queue("dlx-queue");
	}

	@Bean
	public Binding dlxBinding() {
		return BindingBuilder.bind(dlxQueue()).to(dlxExchange()).with("yangye-dlx-routing-key");
	}

}
